import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useCartStore = defineStore('cart', () => {
  const list = ref<any[]>([])
  function addCart(item:any){
    list.value.push(item)
  }
  function removeCartByIds(ids: number[]) {
    console.log(ids);
    
    list.value = list.value.filter((_, index) => !ids.includes(index));
  }
  function removeCart(idx:number){
    list.value.splice(idx,1)
  }
  function clearCart(){
    list.value = [];
  }
  return {
    list,addCart,removeCart,clearCart,removeCartByIds
  }
}, {
  unistorage: true, // 是否持久化
})
